﻿using Microsoft.AspNetCore.StaticFiles;
using Tauren.File.DLL.Base;
using Tauren.File.Entity.Model;
using Tauren.File.Entity.Output;

namespace Tauren.File.Service.FileBLL
{
    public class DownloadService : IDownloadService
    {
        private IBaseDLL business;
        public DownloadService(IBaseDLL baseDLL)
        {
            business = baseDLL;
        }
        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="fileid"></param>
        /// <returns></returns>
        public DownloadModel DownloadFile(long fileid)
        {
            DownloadModel model = null;
            Files files = business.Get<Files>(fileid);
            if (files != null)
            {
                model = new DownloadModel();
                model.Buff = System.IO.File.OpenRead(files.FilePath);
                model.fileName = files.CNName + "." + files.ENName;
                model.ContentType = new FileExtensionContentTypeProvider().Mappings["." + files.Ext];
            }
            return model;
        }
    }
}
